import torch
import matplotlib.pyplot as plt
import numpy as np


def rightness(prediction,label):
    pred=torch.max(prediction.data,1)[1]
    rights=pred.eq(label.data.view_as(pred)).sum()
    return rights,len(label)


def change_image_channels(image):
    # 三通道分离
    if image.mode == 'RGB':
        r, g, b = image.split()

    return r,g,b

def convertL(image):

    #灰度化PIL图片
    #L=0.299R+0.587G+0.114B
    img=image.convert('L')


    return img




def show_arrimg(img):

    plt.imshow(img[0, ...])
    plt.show()

def show_tensorimg(img):
    img=img.numpy()
    show_arrimg(img)

